/**
 * @class Budget
 */ 
var Budget = Class.create(AjaxClient,
{
  /**
   * initialize
   */
  initialize: function()
  {
    this.setServer('budget.ajaxsrv.php');

    this.registerCallbacks();
    
    this.ajaxUpdate('budget', { action: 'load' });
  },
  
  /**
   * registerCallbacks
   */
  registerCallbacks: function()
  {
  },
  
  look_budget_empty: function(id_cat, id_editor)
  {
    new Event.Over('row_cat_' + id_cat);

    this.ajaxInPlaceEditor( "Clic pour créer un budget"
                          , id_editor
                          , { action: 'create', id_cat: id_cat }
                          );
  },

  look_budget_existing: function(id_cat, id_budget, id_editor)
  {
    new Event.Over('row_cat_' + id_cat);

    this.ajaxInPlaceEditor( "Clic pour modifier un budget"
                          , id_editor
                          , { action: 'update', id_budget: id_budget, id_cat: id_cat }
                          );
  },
  
  set_budget: function(id_cat, id_budget, montant)
  {
    var content = '<span id="edit_'+id_cat+'">'+montant+'</span> €';
    $('montant_'+id_cat).update(content);
    
    this.look_budget_existing(id_cat, id_budget, 'edit_'+id_cat);
  },
  
  remove_budget: function(id_cat)
  {
    var content = '<span id="edit_'+id_cat+'">Pas de budget</span>';
    $('montant_'+id_cat).update(content);
    
    this.look_budget_empty(id_cat, 'edit_'+id_cat);
  }
});

Event.observe(window, "load", function(event)
{
  window.Budget = new Budget();
});
